<template>
<div>
<h1>修改密码</h1>
  <form action="" v-model="form" @submit.prevent="upd_pwd">
    <p>请输入你的用户名<input type="text" v-model="form.username" @blur="get_user"></p>
    <p style="color: red">{{error.name}}</p>
    <p>请输入你的手机号<input type="text" v-model="form.mobile" @blur="get_user"></p>
    <p style="color: red">{{error.mobile}}</p>
    <p v-show="is_show">请输入新密码 <input type="text" v-model="form.password"></p>
    <p style="color: red">{{error.pwd}}</p>
    <p v-show="is_show">确认新密码 <input type="text" v-model="form.password1"></p>
    <p style="color: red">{{error.pwd1}}</p>
    <button type="submit">确认修改</button>
  </form>

</div>
</template>

<script>
export default {
  name: "retrieve_1",
  data(){
    return{
      form:{},
      is_show:false,
      error:{name:"",mobile:"",pwd:"",pwd1:""}
    }
  },
  methods:{
    get_user(){
      this.$axios.post('zh_pwd/',this.form)
      .then(res=>{console.log(res)
      if(res.data.code==900){
        this.error.name='用户名不存在'
        return false
      }else {
        this.error.name=""
      }
      if(res.data.code==800){
        this.error.mobile='手机号不一致'
        return false
      }else {
        this.error.mobile=""
      }
      if(res.data.code==200){
        this.is_show=true
      }
      })
    },

    upd_pwd(){
      let reg = /\w{5,20}/
      if (!reg.test(this.form.password)){
        this.error.pwd='密码输入5-20位'
        return false
      }else {
        this.error.pwd=""
      }
      if (this.form.password != this.form.password1){
        this.error.pwd1='密码输入不一致'
        return false
      }else {
        this.error.pwd1=""
        this.$axios.put('zh_pwd/',this.form)
          .then(res=>{console.log(res)
            alert(res.data.meg)
          })
      }
    }
  }
}
</script>

<style scoped>

</style>
